package com.taikang.hmp.hbusiness.diabetes.measure.sport.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.taikang.hmp.hbusiness.diabetes.measure.sport.bean.SportPrescriptionBean;

/**
 * 运动 author:wyf time:2015年8月27日 下午5:07:20
 */
public class SportUtil {
	/**
	 * 
	 * @param dateTime
	 *            格式为"yyyy-mm-dd"的日期格式
	 * @return string类型的前一天的日期
	 * @throws ParseException
	 */
	public static String getFormerDate(Date dateTime, int i)
			throws ParseException {

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		long dif = dateTime.getTime() - 86400 * 1000 * i;
		Date date = new Date();
		date.setTime(dif);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

		return sdf.format(date);
	}
    /**
    * 根据强度取系数
    * @param i
    * @return 系数
    */
	public static double getRatio(int i) {
		double result = 0;
		if(i==0){
			result =0;
		}else 
		if (i <= 105) {
			result = 0.0525;
		} else if (i > 105 && i <= 109) {
			result = 0.0604;
		} else if (i > 109 && i <= 110) {
			result = 0.0683;
		} else if (i > 110 && i <= 119) {
			result = 0.070;
		} else if (i > 119 && i <= 129) {
			result = 0.0874;
		} else if (i > 129 && i <= 130) {
			result = 0.1048;
		} else if (i > 130 && i <= 140) {
			result = 0.105;
		} else if (i > 140 && i <= 149) {
			result = 0.1224;
		} else if (i > 149) {
			result = 0.1398;
		}
		return result;
	}
	/**
	 * 两个日期差了几分钟
	 * @param smdate
	 * @param bdate
	 * @return
	 * @throws ParseException
	 */
	 
	public static int daysBetween(String smdate,String bdate) throws ParseException {  
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        Calendar cal = Calendar.getInstance();    
        cal.setTime(sdf.parse(smdate));    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(sdf.parse(bdate));    
        long time2 = cal.getTimeInMillis();         
        long between_days=(time2-time1)/(1000*60);  
            
       return Integer.parseInt(String.valueOf(between_days));     
    }  
	public static int changeString(String i){
		if(i == null|| "".equals(i)){
			return 0;
		}else {
			return Integer.parseInt(i);
		}
	} 
	public static double changeStringD(String i){
		if(i == null|| "".equals(i)){
			return 0;
		}else {
			return Double.parseDouble(i);
		}
	} 
	
	/**
	 * 根据bmi获取运动处方
	 * @param bmi
	 * @return
	 */
	public static int getPrescriptionByBmi(float bmi){
		if(bmi < 24){
			return 1;
		}else if(bmi >= 28){
			return 3;
		}else{
			return 2;
		}
	}
	/**
	 * 初始化运动处方
	 * @return
	 */
	public List<SportPrescriptionBean> initSportPrescription(){
		List<SportPrescriptionBean> prescription = new ArrayList<SportPrescriptionBean>();
		//处方1
		SportPrescriptionBean model1 = new SportPrescriptionBean();
		model1.setPrescription(1);
		model1.setStage(1);
		model1.setIntensity(100);
		model1.setObject(1000);
		prescription.add(model1);
		SportPrescriptionBean model2 = new SportPrescriptionBean();
		model2.setPrescription(1);
		model2.setStage(2);
		model2.setIntensity(100);
		model2.setObject(1500);
		prescription.add(model2);
		SportPrescriptionBean model3 = new SportPrescriptionBean();
		model3.setPrescription(1);
		model3.setStage(3);
		model3.setIntensity(110);
		model3.setObject(2200);
		prescription.add(model3);
		SportPrescriptionBean model4 = new SportPrescriptionBean();
		model4.setPrescription(1);
		model4.setStage(4);
		model4.setIntensity(110);
		model4.setObject(2750);
		prescription.add(model4);
		SportPrescriptionBean model5 = new SportPrescriptionBean();
		model5.setPrescription(1);
		model5.setStage(5);
		model5.setIntensity(110);
		model5.setObject(3300);
		prescription.add(model5);
		SportPrescriptionBean model6 = new SportPrescriptionBean();
		model6.setPrescription(1);
		model6.setStage(6);
		model6.setIntensity(110);
		model6.setObject(3300);
		prescription.add(model6);
		SportPrescriptionBean model7 = new SportPrescriptionBean();
		model7.setPrescription(1);
		model7.setStage(7);
		model7.setIntensity(110);
		model7.setObject(4400);
		prescription.add(model7);
		SportPrescriptionBean model8 = new SportPrescriptionBean();
		model8.setPrescription(1);
		model8.setStage(8);
		model8.setIntensity(110);
		model8.setObject(4950);
		prescription.add(model8);
		SportPrescriptionBean model9 = new SportPrescriptionBean();
		model9.setPrescription(1);
		model9.setStage(9);
		model9.setIntensity(110);
		model9.setObject(5500);
		prescription.add(model9);
		SportPrescriptionBean model10 = new SportPrescriptionBean();
		model10.setPrescription(1);
		model10.setStage(10);
		model10.setIntensity(130);
		model10.setObject(6500);
		prescription.add(model10);
		SportPrescriptionBean model11 = new SportPrescriptionBean();
		model11.setPrescription(1);
		model11.setStage(11);
		model11.setIntensity(130);
		model11.setObject(7150);
		prescription.add(model11);
		SportPrescriptionBean model12 = new SportPrescriptionBean();
		model12.setPrescription(1);
		model12.setStage(12);
		model12.setIntensity(130);
		model12.setObject(7800);
		prescription.add(model12);
		//处方2
		SportPrescriptionBean model13 = new SportPrescriptionBean();
		model13.setPrescription(2);
		model13.setStage(1);
		model13.setIntensity(105);
		model13.setObject(1050);
		prescription.add(model13);
		SportPrescriptionBean model14 = new SportPrescriptionBean();
		model14.setPrescription(2);
		model14.setStage(2);
		model14.setIntensity(105);
		model14.setObject(1575);
		prescription.add(model14);
		SportPrescriptionBean model15 = new SportPrescriptionBean();
		model15.setPrescription(2);
		model15.setStage(3);
		model15.setIntensity(119);
		model15.setObject(2380);
		prescription.add(model15);
		SportPrescriptionBean model16 = new SportPrescriptionBean();
		model16.setPrescription(2);
		model16.setStage(4);
		model16.setIntensity(119);
		model16.setObject(2975);
		prescription.add(model16);
		SportPrescriptionBean model17 = new SportPrescriptionBean();
		model17.setPrescription(2);
		model17.setStage(5);
		model17.setIntensity(119);
		model17.setObject(3570);
		prescription.add(model17);
		SportPrescriptionBean model18 = new SportPrescriptionBean();
		model18.setPrescription(2);
		model18.setStage(6);
		model18.setIntensity(119);
		model18.setObject(4165);
		prescription.add(model18);
		SportPrescriptionBean model19 = new SportPrescriptionBean();
		model19.setPrescription(2);
		model19.setStage(7);
		model19.setIntensity(110);
		model19.setObject(4760);
		prescription.add(model19);
		SportPrescriptionBean model20 = new SportPrescriptionBean();
		model20.setPrescription(2);
		model20.setStage(8);
		model20.setIntensity(119);
		model20.setObject(5355);
		prescription.add(model20);
		SportPrescriptionBean model21 = new SportPrescriptionBean();
		model21.setPrescription(2);
		model21.setStage(9);
		model21.setIntensity(119);
		model21.setObject(5950);
		prescription.add(model21);
		SportPrescriptionBean model22 = new SportPrescriptionBean();
		model22.setPrescription(2);
		model22.setStage(10);
		model22.setIntensity(140);
		model22.setObject(7000);
		prescription.add(model22);
		SportPrescriptionBean model23 = new SportPrescriptionBean();
		model23.setPrescription(2);
		model23.setStage(11);
		model23.setIntensity(140);
		model23.setObject(7700);
		prescription.add(model23);
		SportPrescriptionBean model24 = new SportPrescriptionBean();
		model24.setPrescription(2);
		model24.setStage(12);
		model24.setIntensity(140);
		model24.setObject(8400);
		prescription.add(model24);
		//处方3
		SportPrescriptionBean model25 = new SportPrescriptionBean();
		model25.setPrescription(3);
		model25.setStage(1);
		model25.setIntensity(109);
		model25.setObject(1090);
		prescription.add(model25);
		SportPrescriptionBean model26 = new SportPrescriptionBean();
		model26.setPrescription(3);
		model26.setStage(2);
		model26.setIntensity(109);
		model26.setObject(1635);
		prescription.add(model26);
		SportPrescriptionBean model27 = new SportPrescriptionBean();
		model27.setPrescription(3);
		model27.setStage(3);
		model27.setIntensity(129);
		model27.setObject(2580);
		prescription.add(model27);
		SportPrescriptionBean model28 = new SportPrescriptionBean();
		model28.setPrescription(3);
		model28.setStage(4);
		model28.setIntensity(129);
		model28.setObject(3225);
		prescription.add(model28);
		SportPrescriptionBean model29 = new SportPrescriptionBean();
		model29.setPrescription(3);
		model29.setStage(5);
		model29.setIntensity(129);
		model29.setObject(3870);
		prescription.add(model29);
		SportPrescriptionBean model30 = new SportPrescriptionBean();
		model30.setPrescription(3);
		model30.setStage(6);
		model30.setIntensity(129);
		model30.setObject(4515);
		prescription.add(model30);
		SportPrescriptionBean model31 = new SportPrescriptionBean();
		model31.setPrescription(3);
		model31.setStage(7);
		model31.setIntensity(129);
		model31.setObject(5160);
		prescription.add(model31);
		SportPrescriptionBean model32 = new SportPrescriptionBean();
		model32.setPrescription(3);
		model32.setStage(8);
		model32.setIntensity(129);
		model32.setObject(5850);
		prescription.add(model32);
		SportPrescriptionBean model33 = new SportPrescriptionBean();
		model33.setPrescription(3);
		model33.setStage(9);
		model33.setIntensity(129);
		model33.setObject(6450);
		prescription.add(model33);
		SportPrescriptionBean model34 = new SportPrescriptionBean();
		model34.setPrescription(3);
		model34.setStage(10);
		model34.setIntensity(149);
		model34.setObject(7550);
		prescription.add(model34);
		SportPrescriptionBean model35 = new SportPrescriptionBean();
		model35.setPrescription(3);
		model35.setStage(11);
		model35.setIntensity(149);
		model35.setObject(8195);
		prescription.add(model35);
		SportPrescriptionBean model36 = new SportPrescriptionBean();
		model36.setPrescription(3);
		model36.setStage(12);
		model36.setIntensity(149);
		model36.setObject(8940);
		prescription.add(model36);
		return prescription;
	}
}
